package com.lagou.numbersort.step2;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class NumSortMapper2 extends Mapper<LongWritable, Text, Text, LongWritable> {
    Text k = new Text();
    LongWritable one = new LongWritable(1);
    //读取原始文件并添加分区信息，与step1中分区相对应
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        long number = Long.parseLong(value.toString());

        if (number < 500){
            k.set("part-r-00000");
        }else if (number>=500 && number<=1000){
            k.set("part-r-00001");
        }else{
            k.set("part-r-00002");
        }
        context.write(k,one);
    }
}
